package com.hyx.api.controller.pc_admin;

import com.hyx.api.domain.Wallet;
import com.hyx.api.service.pc_admin.IWalletService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 钱包Controller
 *
 * @author HK
 * @date 2023-10-25
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/wallet")
public class WalletController extends BaseController {

    private final IWalletService walletService;

    /**
     * 获取钱包详细信息
     */
    @PreAuthorize("@ss.hasPermi('api:wallet:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId) {
        return success(walletService.selectWalletById(userId));
    }

    /**
     * 新增钱包
     */
    @PreAuthorize("@ss.hasPermi('api:wallet:add')")
    @Log(title = "钱包", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@Validated @RequestBody Wallet bo) {
        return toAjax(walletService.insertWallet(bo));
    }
}
